package gui;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import Projektarbete.User;

public class TabbedPanePanel extends JPanel{
	
	public ChatMemberPanel chatMemPanel;
	public MainFrame mf;
	public int chat_id;
	
	public TabbedPanePanel(JTabbedPane pane1, String name, JPanel component1, MainFrame mainframe, int chatId, boolean windowType){
		
		mf = mainframe;
		chat_id = chatId;
		
		JLabel nameLabel = new JLabel(name);
		
		
		ImageIcon ii=new ImageIcon("src/closeButton.png");
		
		final JLabel closeLabel = new JLabel(ii);
		
		final JTabbedPane pane = pane1;
		
		final JPanel component = component1;
		
		final boolean type = windowType;

        /*
         * titlePanel is initialized containing a JLabel with the tab title, 
         * and closeButton. (I don't recall the tabbed pane showing a title itself after 
         * setTabComponentAt() is called)
         */
        JPanel titlePanel = new JPanel();
        
        titlePanel.add(nameLabel);
        titlePanel.add(closeLabel);
        titlePanel.setOpaque(false);
        pane.add(component);
        pane.setTabComponentAt(pane.indexOfComponent(component), titlePanel);

        closeLabel.addMouseListener(new MouseAdapter()  
        {  
        	
        	public void mousePressed(MouseEvent e){
        		
        		ImageIcon iiPressed = new ImageIcon("src/closeButtonClick.png");
        		
        		closeLabel.setIcon(iiPressed);
        		closeLabel.repaint();
        	}
            public void mouseReleased(MouseEvent e)  
            {
            	mf.closeChatTab(chat_id, type);
            	pane.remove(component);
            }
         });
		
		
		
	}


}
